import 'package:flutter_base/base/controller/base_list_more_controller.dart';
import 'package:flutter_base/http/http_export.dart';
import 'package:get/get.dart';

import 'model/recharge_record_model.dart';

class WalletCoinDetailsRechargeLogic extends BaseListMoreController {
  String coinId = '';
  
  @override
  void onInit() {
    super.onInit();
    coinId = Get.arguments?['coinId'] ?? '';
  }
  
  @override
  void onReady() {
    super.onReady();
    refreshList();
  }

  @override
  Future<List> loadData() async {
    // 模拟网络请求获取充值记录
    await Future.delayed(const Duration(seconds: 1));
    
    // 基础测试数据
    List<Map<String, dynamic>> mockData = [
      {
        'id': '1',
        'orderNo': 'R20240610001',
        'amount': '+100',
        'time': '2024-06-10 10:30',
        'status': '充值成功',
      },
      {
        'id': '2',
        'orderNo': 'R20240609002',
        'amount': '+50',
        'time': '2024-06-09 15:45',
        'status': '充值成功',
      },
      {
        'id': '3',
        'orderNo': 'R20240608003',
        'amount': '+200',
        'time': '2024-06-08 09:20',
        'status': '充值成功',
      },
      {
        'id': '4',
        'orderNo': 'R20240607004',
        'amount': '+80',
        'time': '2024-06-07 14:10',
        'status': '充值成功',
      },
      {
        'id': '5',
        'orderNo': 'R20240606005',
        'amount': '+120',
        'time': '2024-06-06 11:35',
        'status': '充值成功',
      },
    ];
    
    // 模拟加载更多数据
    if (pageNum > 1) {
      // 第二页数据
      List<Map<String, dynamic>> pageTwo = [
        {
          'id': '6',
          'orderNo': 'R20240605006',
          'amount': '+90',
          'time': '2024-06-05 16:20',
          'status': '充值成功',
        },
        {
          'id': '7',
          'orderNo': 'R20240604007',
          'amount': '+60',
          'time': '2024-06-04 13:50',
          'status': '充值成功',
        },
        {
          'id': '8',
          'orderNo': 'R20240603008',
          'amount': '+150',
          'time': '2024-06-03 09:40',
          'status': '充值成功',
        },
      ];
      
      // 如果是第二页，返回第二页数据
      if (pageNum == 2) {
        return pageTwo.map((item) => RechargeRecordModel.fromJson(item)).toList();
      }
      
      // 如果页码大于2，返回空列表表示没有更多数据
      return [];
    }
    
    // 真实项目中应该通过API获取数据
    // HttpResponse response = await HttpManager().get(
    //   API.getRechargeRecords,
    //   params: {'coinId': coinId, 'pageNum': pageNum, 'pageSize': pageSize},
    //   fromJson: RechargeRecordModel.fromJson,
    //   uiType: HttpUIType.toast,
    // );
    
    // 返回第一页数据
    return mockData.map((item) => RechargeRecordModel.fromJson(item)).toList();
  }

  @override
  void onClose() {
    // TODO: implement onClose
    super.onClose();
  }
}
